// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Aggregations;

public sealed partial class BucketCorrelationFunctionCountCorrelationIndicator
{
	/// <summary>
	/// <para>
	/// The total number of documents that initially created the expectations. It’s required to be greater
	/// than or equal to the sum of all values in the buckets_path as this is the originating superset of data
	/// to which the term values are correlated.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("doc_count")]
	public int DocCount { get; set; }

	/// <summary>
	/// <para>
	/// An array of numbers with which to correlate the configured <c>bucket_path</c> values.
	/// The length of this value must always equal the number of buckets returned by the <c>bucket_path</c>.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("expectations")]
	public ICollection<double> Expectations { get; set; }

	/// <summary>
	/// <para>
	/// An array of fractions to use when averaging and calculating variance. This should be used if
	/// the pre-calculated data and the buckets_path have known gaps. The length of fractions, if provided,
	/// must equal expectations.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("fractions")]
	public ICollection<double>? Fractions { get; set; }
}

public sealed partial class BucketCorrelationFunctionCountCorrelationIndicatorDescriptor : SerializableDescriptor<BucketCorrelationFunctionCountCorrelationIndicatorDescriptor>
{
	internal BucketCorrelationFunctionCountCorrelationIndicatorDescriptor(Action<BucketCorrelationFunctionCountCorrelationIndicatorDescriptor> configure) => configure.Invoke(this);

	public BucketCorrelationFunctionCountCorrelationIndicatorDescriptor() : base()
	{
	}

	private int DocCountValue { get; set; }
	private ICollection<double> ExpectationsValue { get; set; }
	private ICollection<double>? FractionsValue { get; set; }

	/// <summary>
	/// <para>
	/// The total number of documents that initially created the expectations. It’s required to be greater
	/// than or equal to the sum of all values in the buckets_path as this is the originating superset of data
	/// to which the term values are correlated.
	/// </para>
	/// </summary>
	public BucketCorrelationFunctionCountCorrelationIndicatorDescriptor DocCount(int docCount)
	{
		DocCountValue = docCount;
		return Self;
	}

	/// <summary>
	/// <para>
	/// An array of numbers with which to correlate the configured <c>bucket_path</c> values.
	/// The length of this value must always equal the number of buckets returned by the <c>bucket_path</c>.
	/// </para>
	/// </summary>
	public BucketCorrelationFunctionCountCorrelationIndicatorDescriptor Expectations(ICollection<double> expectations)
	{
		ExpectationsValue = expectations;
		return Self;
	}

	/// <summary>
	/// <para>
	/// An array of fractions to use when averaging and calculating variance. This should be used if
	/// the pre-calculated data and the buckets_path have known gaps. The length of fractions, if provided,
	/// must equal expectations.
	/// </para>
	/// </summary>
	public BucketCorrelationFunctionCountCorrelationIndicatorDescriptor Fractions(ICollection<double>? fractions)
	{
		FractionsValue = fractions;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("doc_count");
		writer.WriteNumberValue(DocCountValue);
		writer.WritePropertyName("expectations");
		JsonSerializer.Serialize(writer, ExpectationsValue, options);
		if (FractionsValue is not null)
		{
			writer.WritePropertyName("fractions");
			JsonSerializer.Serialize(writer, FractionsValue, options);
		}

		writer.WriteEndObject();
	}
}